﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class MaNX_DB
    {
        public static DataTable SelectAllMaNX()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblMaNhapXuat", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblMaNhapXuat", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void Insert(MaNX item)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemMaNX", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemMaNX", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNX", item.Manx);
                command.Parameters.AddWithValue("@DienGiai", item.Diengiai);
                command.ExecuteNonQuery();

            }
        }
        public static void Update(string oldMaNX, MaNX item)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatMaNX", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatMaNX", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNX", oldMaNX);
                command.Parameters.AddWithValue("@DienGiai", item.Diengiai);
                command.ExecuteNonQuery();

            }
        }
        public static void Delete(string oldMaNX)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaMaNX", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaMaNX", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNX", oldMaNX);
                command.ExecuteNonQuery();

            }
        }
    }
}
